//
//  XNTimerLabel.m
//  xndm_proj
//
//  Created by xn on 2021/5/8.
//  Copyright © 2021 Linfeng Song. All rights reserved.
//

#import "XNTimerLabel.h"

@interface XNTimerLabel ()

@property (nonatomic, assign) NSInteger seconds;

@property (nonatomic, strong) XNTimerUIHelper *helper;

@end

@implementation XNTimerLabel

- (XNTimerUIHelper *)helper {
    if (!_helper) {
        _helper = [XNTimerUIHelper new];
        __weak typeof(self) weakSelf = self;
        _helper.showTextBlock = ^(NSString *value) {
            dispatch_async(dispatch_get_main_queue(), ^{
                __strong typeof(self) strongSelf = weakSelf;
                if (self.countDownPrefixText.length >0) {
                    self.text = [NSString stringWithFormat:@"%@%@",self.countDownPrefixText, value];
                }
                else {
                    self.text = value;
                }
            });
        };
    }
    return _helper;
}

- (void)setProgressBlock:(TimerLabelProgressBlock)progressBlock {
    self.helper.progressBlock =  progressBlock;
}

- (void)setDuration:(NSInteger)duration {
    _duration = duration;
    self.helper.duration = duration;
}

- (void)startWithSeconds:(NSInteger)seconds {
    self.helper.seconds = seconds;
    [self.helper startWithSeconds:seconds];
}

- (void)cancelTimer;
{
    [self.helper cancelTimer];
}

@end
